/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Utility;

import CRUD.ComplaintHome;
import CRUD.MemberHome;
import CRUD.ThemeHome;
import java.util.Date;
import xmlMapping.Complaint;
import xmlMapping.Forum;
import xmlMapping.Member;
import xmlMapping.Theme;

/**
 *
 * @author Ruba
 */
public class MemberAccountUtility {

    public void editAccount(Member member){
        new MemberHome().attachDirty(member);
    }

    public Member getAccountById(Integer id){
       Member member = new MemberHome().findById(id);
       return member;
    }

    public Member getAccountByName(String userName){
        MemberHome mHome=new MemberHome();
        Member member = mHome.findByUserName(userName);
        mHome.session.close();
        return member;
    }

    public void sendComplaint(Complaint complaint){
        new ComplaintHome().persist(complaint);
    }

    public static void main(String[] args){
//        MemberAccountUtility acc = new MemberAccountUtility();
//        Member mem = new Member(new ThemeHome().findById(new Integer(1)),"ruba again","password ","mail","mod");
//        mem.setMemberId(new Integer(3));
//        acc.editAccount(mem);
//        System.out.println("#getMem by id test : ret mem name "+acc.getAccountById(new Integer(1)).getUserName());
//        System.out.println("#getAccBUname test : returned member id :"+acc.getAccountByName("ali").getMemberId().toString());
//       //////send complaint test
//       Forum forum = new Forum();
//       forum.setForumId(1);
//       acc.sendComplaint(new Complaint(mem,forum,"RUBA'S COMPLAINT","body of complaint",false,new Date()));
    }
}
